<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html:html>
<head>
<META http-equiv=Pragma content=no-cache>
<META http-equiv=Cache-Control content=no-cache>
<META http-equiv=Expires content=0>
<title><bean:message key="F0302.title"/></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/resource/css/style.css" type="text/css">
<script language="javascript" type="text/javascript" src="../../style/scripts/util.js"></script>
<script language="javascript" type="text/javascript" src="../../resource/calendar/DCDA_C03.js"></script>
<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/Validator.js"></script>
<script language="javascript1.2">
/**重置*/
function ResetMe()
{	
    document.getElementById("manufacturingOrder").className = "MyText";
	document.getElementById("modelName").className = "MyTextReadOnly";
	document.getElementById("previousAdvance").className = "MySelect";
	document.getElementById("groups").className = "MySelect";
	document.getElementById("groupQty").className = "MyTextReadOnly";
	document.getElementById("lastAdvance").className = "MySelect";
	document.getElementById("lastAdvanceDate").className = "MyText";
	
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "none";
	objPrompt.innerHTML = "";
}

//保存 判断
function operation1(){
	ResetMe();
	var manufacturingOrder = document.getElementById("manufacturingOrder").value;
	var modelName = document.getElementById("modelName").value;
	var previousAdvance = document.getElementById("previousAdvance").value;
	var groups = document.getElementById("groups").value;
	var groupQty = document.getElementById("groupQty").value;
	var lastAdvance = document.getElementById("lastAdvance").value;
	var lastAdvanceDate = document.getElementById("lastAdvanceDate").value;
	var lastAdvanceText =0;
	var previousAdvanceText =0;
	var submitFlag = true;
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "block";
    objPrompt.innerHTML = "";
		if(!isNotNull(Jtrim(manufacturingOrder))){
			objPrompt.innerHTML += "<li><bean:message key="common.ManufacturingOrder"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("manufacturingOrder").className = "MyControlError";
			submitFlag = false;
		}
		else{
			if(isNumber(manufacturingOrder)){
				objPrompt.innerHTML += "<li><bean:message key="common.ManufacturingOrder"/><bean:message key="adyh.error.number"/>！";
				document.getElementById("manufacturingOrder").className = "MyControlError";
				submitFlag = false;
			}
		}
	    if(!isNotNull(Jtrim(modelName))){
			objPrompt.innerHTML += "<li><bean:message key="adyh.model"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("modelName").className = "MyControlError";
			submitFlag = false;
		}
		if(!isNotNull(Jtrim(groupQty))){
			objPrompt.innerHTML += "<li><bean:message key="F03.groupQty"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("groupQty").className = "MyControlError";
			submitFlag = false;
		}
		if(!isNotNull(Jtrim(lastAdvanceDate))){
			objPrompt.innerHTML += "<li><bean:message key="F0302.lastAdvanceDate"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("lastAdvanceDate").className = "MyControlError";
			submitFlag = false;
		}
		
		
		if(document.getElementById("lastAdvance").options.length == 0){
			objPrompt.innerHTML += "<li><bean:message key="F0302.lastAdvance"/><bean:message key="adyh.error.isnull"/>！";
			objPrompt.innerHTML += "<li><bean:message key="F0302.previousAdvance"/><bean:message key="adyh.error.isnull"/>！";
			objPrompt.innerHTML += "<li><bean:message key="adyh.groups"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("lastAdvance").className = "MyControlError";
			document.getElementById("previousAdvance").className = "MyControlError";
			document.getElementById("groups").className = "MyControlError";
			submitFlag = false ;
		}
		else{
			if(document.getElementById("groups").value==""){
				objPrompt.innerHTML += "<li><bean:message key="adyh.groups"/><bean:message key="adyh.error.isnull"/>！";
				document.getElementById("groups").className = "MyControlError";
				submitFlag = false ;
			}
			
			if(document.getElementById("lastAdvance").value==""){
				objPrompt.innerHTML += "<li><bean:message key="F0302.lastAdvance"/><bean:message key="adyh.error.isnull"/>！";
				document.getElementById("lastAdvance").className = "MyControlError";
				submitFlag = false ;
			}
			else{
				lastAdvanceText = document.getElementById("lastAdvance").options[document.getElementById("lastAdvance").selectedIndex].text;
				previousAdvanceText = document.getElementById("previousAdvance").options[document.getElementById("previousAdvance").selectedIndex].text;
				if(lastAdvanceText<=previousAdvanceText){
					objPrompt.innerHTML += "<li><bean:message key="F0302.lastAdvance"/><bean:message key="adyh.error.less"/><bean:message key="F0302.previousAdvance"/>！";
					document.getElementById("lastAdvance").className = "MyControlError";
					document.getElementById("previousAdvance").className = "MyControlError";
					submitFlag = false ;
				}
			}	
		}

		if(submitFlag==true){
		   document.forms[0].previousAdvance.disabled=false;
		   if(document.forms[0].layOutType.value=="add"){
	           operation('insert');
	       }else{
	           operation('update');
	       }	
		}	      
}

function initF0302Detail(){
	ResetMe();	
	var URL = "<%=request.getContextPath()%>/pages/F03/F0302.do?operationType=query&manufacturingOrder="+document.forms[0].manufacturingOrder.value;
	//alert(URL);
	var ajaxTree = new ajax();
	ajaxTree.sendData("POST", URL, true, getReturnVal);		
	
}
function getReturnVal(xmlHttp){
	var elementGroup = xmlHttp.responseXML.getElementsByTagName("GROUP");
	var elementAdvance = xmlHttp.responseXML.getElementsByTagName("ADVANCE");
	var elementModel = xmlHttp.responseXML.getElementsByTagName("MODEL");
	
	createElementWithValueGroup(elementGroup);
	createElementWithValuePreviousAdvance(elementAdvance);
	createElementWithValueLastAdvance(elementAdvance);
	createElementWithValueModelName(elementModel);
}
//初始化组信息
function createElementWithValueGroup(element){
        var select = null;
		var option = null;

		// 添加下拉列表 
		if( element.length > 0 ){			
			select = document.getElementById("groups");//页面groups元素
			//消除groups下拉菜单过去的值

			select.options.length = 0;
			// 添加一个空值


			option = document.createElement("option");	
			option.value = "";
			option.text  = "";
			select.options.add(option);						
		
			for(var i=0; i<element.length; i++) {	
				// 为指定标签创建一个元素的实例
				option = document.createElement("option");		
				// 取得元素指定节点的值


				option.value = element[i].childNodes[0].childNodes[0].nodeValue;
				option.text  = element[i].childNodes[1].childNodes[0].nodeValue;		
				// 添加
				select.options.add(option);						
			}		
		}else{
			alert("<bean:message key="F0302.manufactureError"/>");
		}
}
//初始化上一流程信息
function createElementWithValuePreviousAdvance(element){
        var select = null;
		var option = null;

		// 添加下拉列表 
		if( element.length > 0 ){			
			select = document.getElementById("previousAdvance");//页面previousAdvance元素
			//清除previousAdvance下拉菜单过去的值

			select.options.length = 0;
			// 添加一个空值

			option = document.createElement("option");	
			option.value = "";
			option.text  = "";
			select.options.add(option);						
		
			for(var i=0; i<element.length; i++) {	
				// 为指定标签创建一个元素的实例
				option = document.createElement("option");		
				// 取得元素指定节点的值

				option.value = element[i].childNodes[0].childNodes[0].nodeValue;
				option.text  = element[i].childNodes[1].childNodes[0].nodeValue;		
				// 添加
				select.options.add(option);						
			}	
			
		}else{
			//alert("没有此工作号！");
		}
}

//初始化当前流程信息

function createElementWithValueLastAdvance(element){
        var select = null;
		var option = null;

		// 添加下拉列表 
		if( element.length > 0 ){			
			select = document.getElementById("lastAdvance");//页面lastAdvance元素
			//清除lastAdvance下拉菜单过去的值


			select.options.length = 0;
			// 添加一个空值

			option = document.createElement("option");	
			option.value = "";
			option.text  = "";
			select.options.add(option);						
		
			for(var i=0; i<element.length; i++) {	
				// 为指定标签创建一个元素的实例
				option = document.createElement("option");		
				// 取得元素指定节点的值


				option.value = element[i].childNodes[0].childNodes[0].nodeValue;
				option.text  = element[i].childNodes[1].childNodes[0].nodeValue;		
				// 添加
				select.options.add(option);						
			}		
		}else{
			//alert("没有此工作号！");
		}
}

//初始化产品型号信息

function createElementWithValueModelName(element){
        var select = null;
		var option = null;
		// 添加下拉列表 
		if( element.length > 0 ){			
			for(var i=0; i<element.length; i++){	
				// 为指定标签创建一个元素的实例
				document.forms[0].modelName.value =element[i].childNodes[0].childNodes[0].nodeValue;					
			}			
		}else{
			//alert("没有此工作号！");
		}
}

//得到各组数量
function changeselect(groupValue){
     var reValues = new Array();
     reValues = groupValue.split('*');
     document.forms[0].groupQty.value = reValues[1];
     
     var URL = "<%=request.getContextPath()%>/pages/F03/F0302.do?operationType=queryAdvance&manufacturingOrder="+document.forms[0].manufacturingOrder.value+"&groups="+document.forms[0].groups.value;
	 var ajaxTree = new ajax();
	 ajaxTree.sendData("POST", URL, true, dealPreviousAdvance); 
}

function dealPreviousAdvance(xmlHttp){

    document.forms[0].previousAdvance.value = xmlHttp.responseText;
    document.forms[0].previousAdvance.disabled=true;
}

function editInit(){
	if(document.forms[0].operationType.value == "edit"){
		document.forms[0].manufacturingOrder.readOnly = true;
		document.forms[0].manufacturingOrder.className="MyTextReadOnly";
		document.forms[0].groups.disabled = true;
		document.forms[0].previousAdvance.disabled=true;
	}
}

function ShowFormTitle(strTitle){
	document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"height:26px; background-position: left bottom; background-image: url(../../style/images/FormTitle_A_4.gif); background-repeat: repeat-x;\">");
	document.write("  <tr >");
	document.write("	<td style=\"width:5px; background-position: left bottom; background-image: url(../../style/images/FormTitle_A_1.gif); background-repeat: no-repeat;\">&nbsp;&nbsp;&nbsp;</td>");
	document.write("	<td class=\"FormTitle\" style=\"width:100%; padding-left:5px; padding-top:3px; background-position: left bottom; background-image: url(../../style/images/FormTitle_A_2.gif); background-repeat: no-repeat;\">");
	document.write("		<span id=\"spanFormTitle\" class=\"SpanTitle\">"+ strTitle +"</span>");
	document.write("	</td>");
	document.write("	<td style=\"width:5px; background-position: right bottom; background-image: url(../../style/images/FormTitle_A_3.gif); background-repeat: no-repeat;\">&nbsp;&nbsp;&nbsp;</td>");
    document.write("  </tr>");
	document.write("</table>");
}	

</script>
</head>

<body marginheight="0" marginwidth="0" bottommargin="0" topmargin="0" onLoad="javascript:editInit();">
<html:form method="post" action="/pages/F03/F0302.do" enctype="multipart/form-data">
<html:hidden property="operationType"/>
<html:hidden property="layOutType" />
<html:hidden property="id" />

<!--Begin：表单标题-->
<div class="DivBlock">
	<script language="javascript" type="text/javascript">
		ShowFormTitle("<bean:message key="F0302.title"/>");
	</script>
</div>
<!--End：表单标题-->
<!--Begin：表单折叠区块1-->
<div class="DivBlock">
<div class="DivWrap">
  <table  WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
	<tr>	
		<td align="center"><!--工作号码--><bean:message key="common.ManufacturingOrder"/></td>
		<td><html:text property="manufacturingOrder" styleClass="MyText" onchange="javascript:initF0302Detail();"/><span class="Need">*</span></td>
		<td  align="center"><!--产品型号--><bean:message key="adyh.model"/></td>
		<td><html:text property="modelName" styleClass="MyTextReadOnly" readonly="true"/><span class="Need">*</span></td>		
		<td align="center"><!--上一阶段--><bean:message key="F0302.previousAdvance"/></td>
		<td>
		<html:select property="previousAdvance" styleClass="MySelect">
		    <logic:equal name="F0302ActionForm" property="operationType" value="edit">
		       <html:option value=""></html:option>
		       <html:optionsCollection property="previousAdvanceList" value="CODE1" label="NAME1" />
		    </logic:equal>    	 	 
		</html:select>
		</td>		
	</tr>
	<tr>
		<td align="center"><!--组--><bean:message key="adyh.groups"/></td>
		<td>
		<html:select property="groups" styleClass="MySelect" onchange="changeselect(this.value);">
		   <logic:equal name="F0302ActionForm" property="operationType" value="edit">
		       <html:optionsCollection property="groupsList" value="CODE" label="NAME" />
		    </logic:equal>  	 
		</html:select><span class="Need">*</span>
		</td>
		<td align="center"><!--数量--><bean:message key="F03.groupQty"/></td>
		<td><html:text property="groupQty" styleClass="MyTextReadOnly" readonly="true"/><span class="Need">*</span></td>
		<td align="center"><!--当前阶段--><bean:message key="F0302.lastAdvance"/></td>
		<td>
		<html:select property="lastAdvance" styleClass="MySelect">
		    <logic:equal name="F0302ActionForm" property="operationType" value="edit">
		       <html:optionsCollection property="lastAdvanceList" value="CODE1" label="NAME1" />
		    </logic:equal>    		 
		</html:select><span class="Need">*</span>
		</td>
	</tr>
	<tr>
	   <td align="center"><!--更新日期--><bean:message key="F0302.lastAdvanceDate"/></td>
		<td><html:text property="lastAdvanceDate" styleClass="MyText" onclick="return CalendarClick(this)" /><span class="Need">*</span></td>
		<td align="center">&nbsp;</td>
		<td>&nbsp;</td>
		<td align="center">&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
  </table>
</div>
</div>
<!--End：表单折叠区块1-->
<div class="DivBlock">
	<div class="DivButton">
	  <input type="button" name="Submit1" class="MyButton" value="<bean:message key="common.save"/>" onClick="javascript:operation1();">
	  <input type="button" name="Submit2" class="MyButton" value="<bean:message key="common.back"/>" onClick="javascript:operation('back');">
	</div>
	<div class="DivPrompt" id="divPrompt" style="display:none">
	</div>
</div>
</html:form>
</body>
</html:html>